<?php
/**
 * Edit page content
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo
 */
class Minipage_Model_Page
{
    /**
     * Save new page content
     *
     * @return boolean
     */
    static function save($values)
    {
        try {
            $file = 'home/default/minipage/index.';

            if(is_writable($file . 'ini') === FALSE &&
               is_writable($file . 'phtml') === FALSE) {
                throw new Exception();
            }

            // Load header data
            $config = new Zend_Config_Ini(
                              $file . 'ini',
                              null,
                              array(
                                  'skipExtends'        => true,
                                  'allowModifications' => true
                              )
                          );

            $config->head->title = $values["title"];
            $config->head->meta->keywords = $values["keywords"];
            $config->head->meta->description = $values["description"];
            $config->head->meta->author = $values["author"];

            $writer =  new Zend_Config_Writer_Ini(
                           array('config'   => $config,
                                 'filename' => $file . 'ini')
                       );
            $writer->write();

            $handle = fopen($file . 'phtml',"w");
            fwrite($handle, $values["text"]);
            fclose($handle);

            return TRUE;

        } catch (Exception $e) {

            return FALSE;
        }
    }
}